package io.renren.modules.manage.service.impl;

import io.renren.common.utils.R;
import io.renren.modules.manage.controller.UploadController;
import io.renren.modules.manage.service.UploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.Map;

/**
 * @Author: linbd
 * @Description:
 * @Date: 2024/4/24 18:51
 */
@Service
@Slf4j
public class UploadServiceImpl implements UploadService {
    public R deleteFile(String uploadDir,String type, String filename) {
        String filePath = uploadDir + UploadController.SEPARATOR + type + UploadController.SEPARATOR + filename;
        log.info("删除文件：{}", filePath);
        File file = new File(filePath);

        if (file.exists()) {
            if (file.delete()) {
                return R.ok("文件删除成功");
            } else {
                return R.error("文件删除失败");
            }
        } else {
            return R.error("文件不存在");
        }
    }
}
